package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.ShoppingTrolley;
import cn.wolfcode.trip.base.domain.UserOrder;
import cn.wolfcode.trip.base.mapper.ShoppingTrolleyMapper;
import cn.wolfcode.trip.base.mapper.UserOrderMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IShoppingTrolleyService;
import cn.wolfcode.trip.base.service.IUserOrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Service
public class ShoppingTrolleyServiceImpl implements IShoppingTrolleyService {

    @Autowired
    private ShoppingTrolleyMapper shoppingTrolleyMapper;


    @Override
    public void saveOrUpdate(ShoppingTrolley u) {
        if(u.getId()==null){
            shoppingTrolleyMapper.insert(u);
        }else {
        }
    }

    @Override
    public PageInfo<ShoppingTrolley> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<ShoppingTrolley> list = shoppingTrolleyMapper.selectForList(qo);
        return new PageInfo<ShoppingTrolley>(list);
    }

    @Override
    public PageInfo<ShoppingTrolley> selectShoppingsById(Long id,QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<ShoppingTrolley> list = shoppingTrolleyMapper.selectShoppingsById(id,qo);
        return new PageInfo<ShoppingTrolley>(list);
    }


    @Override
    public void bathchDelete(Long[] ids) {
        shoppingTrolleyMapper.bathchDelete(ids);
    }

    @Override
    public List<ShoppingTrolley> bathchGet(Long[] ids) {
        //创建list用于存储查出来的数据
        List<ShoppingTrolley> list = new ArrayList<>();
        for (Long id : ids) {
            ShoppingTrolley shop = shoppingTrolleyMapper.selectByPrimaryKey(id);
            list.add(shop);
        }
        return list;
    }

    @Override
    public void deleteShoppingById(Long id) {
        shoppingTrolleyMapper.deleteByPrimaryKey(id);
    }

}
